package com.lovo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class LogAspect {
    @Pointcut("execution(* com.lovo..*(..))")
    public void logPointcut(){}

//    @Before("logPointcut()")
    public void printLog(){
        log.debug("进入方法");
    }

    @Around("logPointcut()")
    public Object printLog(ProceedingJoinPoint joinPoint) throws Throwable {
        log.debug("进入方法"+joinPoint.getSignature());
        Object obj = null;
        try {
           obj = joinPoint.proceed(joinPoint.getArgs());

        } catch (Throwable throwable) {
            log.error("抛出异常"+throwable);
            throwable.printStackTrace();
            throw throwable;
        }
        log.debug("退出方法"+joinPoint.getSignature());
        return obj;
    }

}
